package com.xqls.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xqls.dal.dao.RolePermissionKeyDao;
import com.xqls.dal.model.RolePermissionExample;
import com.xqls.dal.model.RolePermissionExample.Criteria;
import com.xqls.dal.model.RolePermissionKey;
import com.xqls.service.RolePermissionKeyService;

@Service
public class RolePermissionKeyServiceImpl implements RolePermissionKeyService {

	@Autowired private RolePermissionKeyDao rolePermissionDao;
	
	@Override
	public boolean insertByList(List<RolePermissionKey> list) {
		return this.rolePermissionDao.insertByList(list);
	}

	@Override
	public boolean updateRecord(RolePermissionKey rolePermissionKey,String oldPermId) {
		RolePermissionExample example=new RolePermissionExample();
		Criteria criteria = example.createCriteria();
		criteria.andRoleIdEqualTo(rolePermissionKey.getRoleId());
		criteria.andPermIdEqualTo(oldPermId);
		return this.rolePermissionDao.updateRecord(rolePermissionKey,example);
	}


	@Override
	public boolean deleteById(String roleId) {
		return this.rolePermissionDao.deleteById(roleId);
	}

	@Override
	public boolean deleteRecord(RolePermissionKey key) {
		return this.rolePermissionDao.deleteRecord(key);
	}
	
	@Override
	public boolean deleteByList(List<RolePermissionKey> list) {
		return this.rolePermissionDao.deleteByList(list);
	}

	@Override
	public List<RolePermissionKey> getListByKey(List<String> roleIdList,List<String> permIdList) {
		RolePermissionExample example=new RolePermissionExample();
		Criteria criteria = example.createCriteria();
		criteria.andRoleIdIn(roleIdList);
		criteria.andPermIdIn(permIdList);
		
		return this.rolePermissionDao.getList(example);
	}
	
	@Override
	public RolePermissionKey getLastRecord() {
		return this.rolePermissionDao.getLastRecord();
	}
	
	@Override
	public List<RolePermissionKey> getList() {
		RolePermissionExample example=new RolePermissionExample();
		return this.rolePermissionDao.getList(example);
	}
	
	@Override
	public List<Map<String, Object>> getListByRoleId(String roleId) {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("roleId", roleId);
		return this.rolePermissionDao.getListByMap(map);
	}
	
	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.rolePermissionDao.getListByMap(map);
	}

	@Override
	public List<Map<String, Object>> getMenuByMap(Map<String, Object> map) {
		return this.rolePermissionDao.getMenuByMap(map);
	}

	@Override
	public boolean deleteByMap(Map<String, Object> map) {
		return this.rolePermissionDao.deleteByMap(map);
	}
}
